/*
 * @Date: 2023-08-20 19:32:51
 * @LastEditors: Wangjun
 * @LastEditTime: 2023-08-25 16:35:51
 * @FilePath: \nodex\nodemath\op_abs.go
 * @Description:
 */
package nodemath

import (
	"math"

	"gitee.com/hnxr_1/nodex"
)

func init() {
	nodex.Reister(new(Abs))
}

type Abs struct {
	nodex.Node
	X1 nodex.Double `remark:"输入1"`
	Y  nodex.Double `remark:"输出Y,,out"`
}

func (m *Abs) GetModelID() int {
	return nodex.ModMath
}

/**
 * @description:
 * @return {*}
 */
func (m *Abs) GetName() string {
	return "ABS"
}
func (m *Abs) RegData() []byte {
	return nodex.MakeRegData(m, "绝对值运算", m.GetName(), "")
}

func (m *Abs) Calc() (err error) {
	if m.EnQ {
		if *m.X1.Bad {
			m.Bad = true
			return //不计算
		}
	}

	m.Bad = false
	m.Y.Value = math.Abs(m.X1.Value)
	return
}
